<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="../../../static/css/style.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li>仓库管理</li>
        <li>出库管理</li>
        <li>添加出库</li>
    </ul>
</div>
<div class="formbody">
    <div class="formtitle"><span>出库信息</span></div>
    <ul class="forminfo">
        <li>
            <label>订单编号</label>
            <input maxlength="50" name="" id="indent" type="text" class="dfinput" onblur="state()"/>
            &nbsp;&nbsp;
            <a onclick="toDetail(this)" title="点击查看订单详细信息" class="tablelink">详情</a>
            <i id="alert">必须是审核通过的订单</i>
        </li>
        <li>
            <label>仓库</label>
            <select id="cName" class="dfselect">
                <option value=""></option>
                <option>南京21号仓库</option>
                <option>武汉71号仓库</option>
                <option>天津83号仓库</option>
            </select>
            <i>必选</i>
        </li>
        <li>
            <label>出库时间</label>
            <input name="" id="time1" type="date" class="dfinput"/> <input name="" id="time2" type="time"
                                                                           class="dfinput"/>
            <i>必填</i>
        </li>
        <li>
            <label>出库人</label>
            <input name="" type="text" id="users" value="马云" readonly="readonly" class="roinput"/>
            <i>不能编辑</i>
        <li>
            <label>&nbsp;</label>
            <input name="" type="button" onclick="submitMessage()" class="btn" value="确定"/>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="/ckWarehouse/lists"><input name="" type="button" class="btn" value="返回"/></a>
        </li>
    </ul>
</div>
</body>
<script type="text/javascript" src="../../../static/js/jquery.js"></script>
<script>
    loadstorage()

    //跳转详情页
    function toDetail(target){
        let indent=$('#indent').val();
        $.ajax({
            url: "/sales/custom",
            method: "post",
            dataType: "json",
            data: {orderid: indent},
            success: function (result) {
                if (result.data.data[0]!=null){
                    location.href=href="/market/order/orderView?orderid="+indent;
                }else {
                    alert("订单不存在！")
                }
            }
        })
    }

    //加载仓库列表,用户
    function loadstorage() {
        $.ajax({
            url: "/Warehouse/WarehouseList",
            type: "get",
            dataType: "json",
            success: (pb) => {
                let store = new Array();
                store = pb.data;
                $("#cName").html('')
                store.forEach((item, index) => {
                    $("#cName").append(`<option name="${item.id}" value="${item.id}">${item.cname}</option>`)
                })
            }
        })
        var nowUser = JSON.parse(localStorage.getItem("user"));//当前用户
        $('#users').val(nowUser.uname);
    }

    //失去焦点判断订单状态
    function state() {
        // alert()
        $.ajax({
            url: "/OutWarehouse/queryOrderState",
            type: "get",
            data: {
                indent: $('#indent').val()
            },
            dataType: "json",
            success: (pb) => {
                // alert(pb.data.ddState)
                if (pb.data !="") {
                    if (pb.data.ddState == 2) {
                        console.log(pb.data.ddState)
                        console.log(pb.data.status)
                        if (pb.data.status == 0) {
                            $('#indent').focus();
                            $('#alert').html("该订单未审核!")
                        }
                        if (pb.data.status == 1) {
                            $('#indent').focus();
                            $('#alert').html("该订单在审核中!")
                        }
                        if (pb.data.status == 2) {
                            // $('#indent').focus();
                            $('#alert').html("该订单已审核通过!")
                        }
                        if (pb.data.status == 3) {
                            $('#indent').focus();
                            $('#alert').html("该订单审核未通过!")
                        }

                    } else if (pb.data.ddState == 1) {
                        $('#indent').focus();
                        $('#alert').html("该订单已出库!")
                    }
                }else {
                    $('#indent').focus();
                    $('#alert').html("订单不存在!")
                }
            }
        })
    }

    //添加出库
    function submitMessage() {
        var nowUser = JSON.parse(localStorage.getItem("user"));//当前用户
        $('#users').val(nowUser.uname);
        let nowUserID = nowUser.uid;

        // alert($('#indent').val())
        // alert($('#cName option:selected').attr('name'))
        // alert($('#time1').val()+' '+$('#time2').val()+':00')   //2022-11-04 18:40  yyyy-MM-dd HH:mm:ss
        // alert(nowUserID)

        $.ajax({
            url: "/OutWarehouse/OutWarehouseAdd",
            type: "get",
            dataType: "json",
            data: {
                indent: $('#indent').val(),//订单ID
                WarehouseID: $("#cName option:selected").attr("name"),
                OutTime: $('#time1').val() + ' ' + $('#time2').val() + ':00',  //2022-11-04 18:40  yyyy-MM-dd HH:mm:ss
                userID: nowUserID
            },
            success: (pb) => {
                // $("#users").html(data);
                alert(pb.msg);
            }
        })
    }
</script>
</html>
